package com.batchplatform.department.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.batchplatform.common.entity.department.Department;
import com.batchplatform.department.service.DeptService;

@Controller
public class DepartmentController {
	@Autowired
	private DeptService deptService;

	@RequestMapping("/displayDepartMent.do")
	public String displayUser(Model model) {
		model.addAttribute("departmentList", deptService.getDepartments());
		return "department/manage/departments";
	}
	
	@RequestMapping("/toAddDepartment")
    public String toAdd(Model model){
        return "department/manage/addDepartment";
    }
	

	@RequestMapping("/saveDep.do")
	public String saveDepartment(Department dept, Model model) {
		deptService.addDepartment(dept);
		return displayUser(model);
	}

	@RequestMapping("/updateDep.do")
	public String updatePassword(Department dept, Model model) {
		deptService.updateDepartment(dept);
		return displayUser(model);
	}

	@RequestMapping("/deleteDep.do")
	public String deleteUser(int id, Model model) {
		deptService.deleteDepartments(id);
		return displayUser(model);
	}

}
